#include "server.hpp"

void Buffer_test()
{
    Buffer buf;
    for (int i = 0; i < 200; i++)
    {
        std::string str = "hello world " + std::to_string(i) + '\n';
        buf.WriteStringAndPush(str);
        // std::cout<<"WritePosition: "<<buf._writer_idx<<std::endl;
    }

    while (buf.ReadAbleSize() > 0)
    {
        std::string line = buf.GetOneLineAndPop();
        std::cout << line;
    }
    std::string tmp = buf.ReadAsStringAndPop(buf.ReadAbleSize());
    std::cout << tmp << std::endl;
    // Buffer buf;
    // std::string str = "hello word";
    // buf.WriteStringAndPush(str);

    // Buffer buf1;
    // buf1.WriteBufferAndPush(buf);

    // std::string tmp;
    // tmp = buf1.ReadAsStringAndPop(buf.ReadAbleSize());

    // std::cout << tmp << std::endl;
    // std::cout << buf.ReadAbleSize() << std::endl;
    // std::cout << buf1.ReadAbleSize() << std::endl;
}

#define INF 0
#define BEBUG 1
#define ERROR 2
#define DEFAULT_LOG_LEVEL INF

#define LOG(level, format, ...)                             \
    do                                                      \
    {                                                       \
        if (DEFAULT_LOG_LEVEL > level)                      \
            break;                                          \
        time_t t = time(nullptr);                           \
        struct tm *lt = localtime(&t);                      \
        char buffer[32] = {0};                              \
        strftime(buffer, 31, "%H:%M:%S", lt);               \
        fprintf(stderr, "[%s %s:%d] " format "\n",          \
                buffer, __FILE__, __LINE__, ##__VA_ARGS__); \
    } while (0)

#define ILOG(format, ...) LOG(INF, format, ##__VA_ARGS__)
#define DLOG(format, ...) LOG(BEBUG, format, ##__VA_ARGS__)
#define ELOG(format, ...) LOG(ERROR, format, ##__VA_ARGS__)

int main()
{
    std::string str = "hhh";
    DLOG("dd %s", str.c_str());
    LogMessage(NORMAL,"dd %s", str.c_str());

    char buffer2[32] = "aaaaaaaa";
    DLOG("dddddddddd: %s", buffer2);
    LogMessage(NORMAL,"dddddddddd: %s", buffer2);

    DLOG("sssssss");
    LogMessage(NORMAL,"sssssss");

    return 0;
}